<template>
  <div id="app">
    <h1>运行日志表列表</h1>
    <!--  <vxe-toolbar>
      <template v-slot:buttons>
        <el-button  icon="el-icon-plus" @click="handleAdd()">新增</el-button>
      </template>
    </vxe-toolbar> -->
    <vxe-table
      border
      show-header-overflow
      show-overflow
      highlight-hover-row
      :align="allAlign"
      :data="tableData"
      row-id="id"
      height="480"
      size="medium"
      :loading="loading"
      ref="xTable1"
    >
      <vxe-table-column
        field="ID"
        type="checkbox"
        width="60"
      ></vxe-table-column>
      <vxe-table-column type="seq" title="序号" width="60"></vxe-table-column>
      <vxe-table-column
        field="PROJECT_ID"
        title="工程ID"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="LOG_CODE"
        title="日志编号"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="PROJECT_PARAMETER"
        title="工程参数"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="SOURCE_DATA"
        title="源数据"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="START_TIME"
        title="运行开始时间"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="END_TIME"
        title="运行结束时间"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="RUN_USER_ID"
        title="运行用户ID"
        width="100"
      ></vxe-table-column>
      <vxe-table-column
        field="SUCCESS_FAIL_FLAG"
        title="成功失败标志"
        width="100"
        :formatter="formatterFlag"
      >

      </vxe-table-column>
      <vxe-table-column
        field="ERROR_MSG"
        title="错误消息"
        width="100"
      ></vxe-table-column>
      <vxe-table-column title="操作" width="100" show-overflow>
        <template v-slot="{ row }">
          <i v-if="row.SUCCESS_FAIL_FLAG==='1'" class="el-icon-download" @click="handleDownload(row)"></i>
        </template>
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      border
      size="medium"
      :loading="loading"
      :current-page="tablePage.pageNo"
      :page-size="tablePage.pageSize"
      :total="tablePage.totalResult"
      :layouts="[
        'PrevPage',
        'JumpNumber',
        'NextPage',
        'FullJump',
        'Sizes',
        'Total'
      ]"
      @page-change="handlePageChange"
    >
    </vxe-pager>
  </div>
</template>

<script>
import request from "../utils/request";
import {baseUrl} from "../utils/env";

export default {
  name: "runlog",
  methods: {
    handleAdd() {
      this.$router.push({ path: "/runlog/add" });
    },
    formatterFlag({cellValue}){
      if(cellValue=='1') {
        return '成功';
      }else{
        return '失败';
      }
    },
    //装入表格数据
    loadTableData() {
      var userId = localStorage.userId;
      const that = this;
      request({
        method: "POST",
        url: `/api/Runlog/listPage?userId=${userId}&pageNo=${that.tablePage.pageNo}&pageSize=${that.tablePage.pageSize}`,
      })
        .then(res => {
          if (res.data.status == "1") {
            that.tableData = res.data.list;
            that.tablePage.totalResult = res.data.count;
            this.$message(res.data.message);
          } else {
            this.$message(res.data.message);
            return false;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    handleDownload(row) {
      console.log(row);
        window.open(
          `${this.downloadUrl}?id=${row.ID}`
      )
    },
    handlePageChange({ currentPage, pageSize }) {
      this.tablePage.pageNo = currentPage;
      this.tablePage.pageSize = pageSize;
      this.loadTableData();
    }
  },

  data() {
    return {
      allAlign: null,
      tableData: [],
      loading: false,
      tablePage: {
        pageNo: 1,
        pageSize: 10,
        totalResult: 0
      },
      downloadUrl:baseUrl+"/api/Runlog/downloadById"
    };
  },
  mounted() {
    this.loadTableData();
  }
};
</script>

<style scoped></style>

